package com.demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.domain.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentDao extends BaseMapper<Comment> {
//    增加对应id的评论的点赞数
    @Update("update tb_comment c set c.c_likes=c.c_likes+1 where c.c_id = #{id}")
    void incrementLikes(Long id);
//    减少对应id的评论的点赞数
    @Update("update tb_comment c set c.c_likes=c.c_likes-1 where c.c_id = #{id}")
    void decrementLikes(Long id);

    //更改用户的评论信息都为已查看的状态
    @Update("UPDATE tb_comment\n" +
            "SET c_read_status = 1\n" +
            "WHERE c_read_status = 0 AND c_id=#{id}")
    int updateHadViewed(Long id);

    //计算对应id的未读消息数
    @Select("SELECT COUNT(*) AS total_count  \n" +
            "FROM tb_comment  \n" +
            "WHERE c_read_status = 0 AND c_pid=#{pid};")
    int countNotViewComment(Long pid);

    @Select("SELECT c_id FROM tb_comment c where c.c_pid = #{pid} and c.c_del_flag = 0")
    List<Long> selectCidByPid(Long pid);

    @Select("SELECT c_id FROM tb_comment c where c.c_pid = #{pid} AND c_read_status = 0 AND c.c_del_flag = 0")
    List<Long> selectNotReadCommentByPid(Long pid);
}
